/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachinesystem.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import warmachinesystem.ArmyList;
import warmachinesystem.GameSystem;
import warmachinesystem.SpecialRule;
import warmachinesystem.WarmachineSystemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Game System</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachinesystem.impl.GameSystemImpl#getArmies <em>Armies</em>}</li>
 *   <li>{@link warmachinesystem.impl.GameSystemImpl#getName <em>Name</em>}</li>
 *   <li>{@link warmachinesystem.impl.GameSystemImpl#getSpecialRules <em>Special Rules</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GameSystemImpl extends EObjectImpl implements GameSystem {
	/**
	 * The cached value of the '{@link #getArmies() <em>Armies</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getArmies()
	 * @generated
	 * @ordered
	 */
	protected EList<ArmyList> armies;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getSpecialRules() <em>Special Rules</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSpecialRules()
	 * @generated
	 * @ordered
	 */
	protected EList<SpecialRule> specialRules;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GameSystemImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachineSystemPackage.Literals.GAME_SYSTEM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ArmyList> getArmies() {
		if (armies == null) {
			armies = new EObjectContainmentWithInverseEList<ArmyList>(ArmyList.class, this, WarmachineSystemPackage.GAME_SYSTEM__ARMIES, WarmachineSystemPackage.ARMY_LIST__GAME_SYSTEM);
		}
		return armies;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.GAME_SYSTEM__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SpecialRule> getSpecialRules() {
		if (specialRules == null) {
			specialRules = new EObjectContainmentEList<SpecialRule>(SpecialRule.class, this, WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES);
		}
		return specialRules;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getArmies()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				return ((InternalEList<?>)getArmies()).basicRemove(otherEnd, msgs);
			case WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES:
				return ((InternalEList<?>)getSpecialRules()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				return getArmies();
			case WarmachineSystemPackage.GAME_SYSTEM__NAME:
				return getName();
			case WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES:
				return getSpecialRules();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				getArmies().clear();
				getArmies().addAll((Collection<? extends ArmyList>)newValue);
				return;
			case WarmachineSystemPackage.GAME_SYSTEM__NAME:
				setName((String)newValue);
				return;
			case WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES:
				getSpecialRules().clear();
				getSpecialRules().addAll((Collection<? extends SpecialRule>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				getArmies().clear();
				return;
			case WarmachineSystemPackage.GAME_SYSTEM__NAME:
				setName(NAME_EDEFAULT);
				return;
			case WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES:
				getSpecialRules().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.GAME_SYSTEM__ARMIES:
				return armies != null && !armies.isEmpty();
			case WarmachineSystemPackage.GAME_SYSTEM__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case WarmachineSystemPackage.GAME_SYSTEM__SPECIAL_RULES:
				return specialRules != null && !specialRules.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //GameSystemImpl
